package com.baizhiedu.baizhiappsys.dao.impl;

import com.baizhiedu.baizhiappsys.dao.CourseDao;
import com.baizhiedu.baizhiappsys.entity.Course;
import com.baizhiedu.baizhiappsys.orm.CourseRowMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author lby
 */
@Repository
public class CourseDaoImpl implements CourseDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;


    @Override
    public int selectCourseTotal() {
        //        查询全部的sql
        String sql = "select COUNT(*) from t_course";

        int total = jdbcTemplate.queryForObject(sql, Integer.class);
        return total;
    }

    @Override
    public List<Course> selectCourseOrderByCourseNumberStudents() {
        String sql = "SELECT * FROM t_course ORDER BY course_number_students desc LIMIT 5";

        List<Course> query = jdbcTemplate.query(sql, new CourseRowMapper());

        return query;
    }
}
